# 红酒数据集
from sklearn.datasets import load_wine
# KNN分类算法
from sklearn.neighbors import KNeighborsClassifier
# 分割训练集和数据集
from sklearn.model_selection import train_test_split
import numpy as np

wine_dataset=load_wine()

print("红酒数据集的键： \n{}".format(wine_dataset.keys()))
print("数据集描述： \n{}".format(wine_dataset['data'].shape))

# 分割数据集，训练集：测试集 = 8：2
X_train,X_test,Y_train,Y_test=train_test_split(wine_dataset['data'], wine_dataset['target'], test_size=0.2, random_state=0)


KNN=KNeighborsClassifier(n_neighbors=10)
KNN.fit(X_train, Y_train)

score = KNN.score(X_test, Y_test)

print(score)

X_wine_test=np.array([[11.8,4.39,2.39,29,82,2.86,3.53,0.21,2.85,2.8,.75,3.78,490]])

predict_result=KNN.predict(X_wine_test)

print(predict_result)

print("分类结果：{}".format(wine_dataset['target_names'][predict_result]))

